package com.yxt.function_sdk_share.util;

import android.app.Activity;
import android.view.Gravity;

import com.alibaba.android.arouter.launcher.ARouter;
import com.md.album.db.SelfAlbumManager;
import com.md.basedpc.routerservice.NotifyService;
import com.yxt.function_sdk_share.BottomPopupWindow;
import com.yxt.function_sdk_share.callback.SinglePopupCallBack;
import com.yxt.function_sdk_share.constants.SINGLE_AUDIO_TYPE;
import com.md.network.api.Audio;
import java.util.ArrayList;

import static com.md.basedpc.constant.BaseConstant.SELF_CREATE_ALBUM;

public class BottomPopupUtil {

    public static void shareWithWindows(final Activity activity, SINGLE_AUDIO_TYPE[] share_types1,String albumId, Audio audio, final SinglePopupCallBack shareCallBack) {
        SINGLE_AUDIO_TYPE[] share_types = share_types1.clone();
        BottomPopupWindow menuWindow = new BottomPopupWindow(activity, share_types, new BottomPopupWindow.PopupWindowItemClick() {
            @Override
            public void clickCallBack(int pos, SINGLE_AUDIO_TYPE share_type) {
                if (shareCallBack != null) {
                    shareCallBack.onClick(pos, share_type);
                }
                if (share_type == SINGLE_AUDIO_TYPE.ADD) {
                    ArrayList<Audio> audioArrayList = new ArrayList();
                    audioArrayList.add(audio);
                    ARouter.getInstance()
                            .build("/album/albumlist")
                            .withParcelableArrayList("SELECTED_AUDIOS", audioArrayList)
                            .navigation();

                }else if (share_type == SINGLE_AUDIO_TYPE.DELETE) {
                    SelfAlbumManager.getIns().deleteAudioFromSelfAlbum(albumId,audio.getId());
                    ARouter.getInstance().navigation(NotifyService.class).selfAlbumUpdateSuc(SELF_CREATE_ALBUM);
                }
            }
        });
        //设置layout在PopupWindow中显示的位置
        menuWindow.showAtLocation(activity.getWindow().getDecorView().findViewById(android.R.id.content), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }
}
